package com.supermap.dataservice.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


/**
 * Created by Administrator on 2020-01-09.
 */
public class NearestPoint {


    public static Double getTwoPointDistanceSquare(double x1, double y1, double x2, double y2) {
        return (x1 - x2) * (x1 - x2) + (y1 - y2)*(y1 - y2);
    }
    public static String  getNearestStationNo(double x, double y, List<Point> lonLatArr) throws IOException {

        double min_dis = Double.MAX_VALUE;
        String nearest_stationNo = "";
        for(Point p : lonLatArr) {
            Double dis = getTwoPointDistanceSquare(p.x, p.y, x, y);
            if(min_dis > dis) {
                nearest_stationNo = p.stationNo;
                min_dis = dis;
            }
        }
        return nearest_stationNo;
    }




}
